<style scoped>
.layout {
    border: 1px solid #d7dde4;
    background: #f5f7f9;
    position: relative;
}

.layout-breadcrumb {
    padding: 10px 15px 0;
}

.layout-content {
    min-height: 200px;
    margin: 15px;
    background: #fff;
    border-radius: 4px;
}

.layout-content-main {
    min-height: 730px;
    max-height: 730px;
    overflow: auto;
    padding: 10px;
}

.layout-copy {
    text-align: center;
    padding: 10px 0 20px;
    color: #9ea7b4;
}

.layout-menu-left {
    background: #464c5b;
}

.layout-logo-left {
    width: 90%;
    height: 30px;
    background: #5b6270;
    border-radius: 3px;
    margin: 15px auto;
}
</style>
<template>
    <div id="app" class="layout">
        <Row type="flex">
            <i-col span="5" class="layout-menu-left">
                <Menu accordion theme="dark" width="auto" :open-names="['mailManage']" @on-select="menuSelected">
                    <div class="layout-logo-left"></div>
                    <Submenu v-for="menu in menuData" key="menu.key" v-bind:name="menu.key">
                        <template slot="title"><Icon type="ios-navigate"></Icon>{{menu.submenu}}</template>
                        <Menu-item v-for="menuItem in menu.items" 
                                   key="menuItem.key" 
                                   v-bind:name="menuItem.key">
                            {{menuItem.name}}
                        </Menu-item>
                    </Submenu>
                </Menu>
            </i-col>
            <i-col span="19">
                <div class="layout-breadcrumb">
                    <Breadcrumb>
                        <Breadcrumb-item href="#">{{breadcrumbOne}}</Breadcrumb-item>
                        <Breadcrumb-item href="#">{{breadcrumbTwo}}</Breadcrumb-item>
                    </Breadcrumb>
                </div>
                <div class="layout-content">
                    <div class="layout-content-main">
                        <router-view></router-view>
                    </div>
                </div>
                <div class="layout-copy">
                    2011-2016 &copy; TalkingData
                </div>
            </i-col>
        </Row>
    </div>
</template>

<script>
import AllMails from '@/components/AllMails'

export default {
    data(){
        return {
            menuData:[
                {
                    key:'mailManage',
                    submenu:'邮件管理',
                    items:[
                        {key:'mailManage-saveMailManage',name:'收件管理',url:'/saveMailManage'},
                        {key:'mailManage-sendMailManage',name:'发件管理',url:'/sendMailManage'}
                    ]
                },
                {
                    key:'systemSetting',
                    submenu:'系统设置',
                    items:[
                        {key:'systemSetting-mailBoxConfig',name:'收件箱设置',url:'/mailBoxConfig'},
                        {key:'systemSetting-cacheSetting',name:'缓存设置'}
                    ]
                }
            ],
            breadcrumbOne:'邮件管理',
            breadcrumbTwo:'收件管理'
        }
    },
    created:function(){
        console.log("主界面初始化...");
    },
    methods:{
        //菜单被选着
        menuSelected:function(name){
            console.log("menuSelected:"+name);
            var url = "/"+name.split('-')[1]
            this.$router.push(url);
            //设置右侧面包屑导航
            this.setMenuNameByMenuKey(name);
        },
        setMenuNameByMenuKey:function(menuKey){
            for(let i=0;i<this.menuData.length;i++){
               var menuItems = this.menuData[i].items;
               for(let j=0;j<menuItems.length;j++){
                   var itemKey = menuItems[j].key;
                   if(itemKey === menuKey){
                       this.breadcrumbOne = this.menuData[i].submenu;
                       this.breadcrumbTwo = menuItems[j].name;
                   }
               }
            }
        }
    },
    components: {
        AllMails
    }
}
</script>
